import requests
import json

url_prefix_api = 'http://cloud/prod-api'
path_login = '/api/v1/auth/login'
username = 'admin'
password = '123123'
# 登录获取Token
resp = requests.post(url_prefix_api+path_login, params={'username': username, 'password': password})

if resp.status_code == 200:
    resp_data = json.loads(resp.content)
    accessToken = resp_data['data']['accessToken']
    tokenType = resp_data['data']['tokenType']
    print(f"accessToken:{accessToken}, tokenType:{tokenType}")

    # 获取任务列表，按分类-任务两级目录
    path = '/api/task'
    req_get_tasks = {"operation": "get", "all": True}
    headers = {'Content-type': 'application/json', 'Authorization': f"{tokenType} {accessToken}"}

    resp = requests.post(url_prefix_api + path, json.dumps(req_get_tasks), headers=headers)
    if resp.status_code == 200:
        resp_data = json.loads(resp.content)
        print(json.dumps(resp_data['data'], ensure_ascii=False, indent='  '))
else:
    print(resp.content)
